package com.demo.io;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriteAndRead {

    private int a;
    private int b;
    FileWriteAndRead(){}
    FileWriteAndRead(int a){
        this.a = a;
    }
    FileWriteAndRead(int a,int b){
        this(2);//构造方法之间的调用只能放在构造方法中的第一行
        this.a = a;
        this.b = b;
    }
    public static void main(String[] args) {
        FileWriteAndRead fileWriteAndRead = new FileWriteAndRead();
        try {
            fileWriteAndRead.fileWriterTest();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void fileWriterTest() throws IOException {
        File file = new File("F:\\java学习\\基础班\\图片\\a.txt");
        FileReader fr = new FileReader(file);
//        int read = fr.read();
//        System.out.println(read);
        FileWriter fw = new FileWriter("F:\\java学习\\基础班\\图片\\b.txt",true);
        char[] chs = new char[1024];
        int len;
        while((len = fr.read(chs)) != -1){
            fw.write(chs,0,len);
            fw.flush();
        }
        fw.write("梦想的天空分外蓝");
        System.out.println("梦想的天空分外蓝");
        fw.close();
        fr.close();
    }
}
